<?php

class Poi extends Controller{

	function poi()
	{
		parent::Controller();
		$this->load->helper('url');
		$this->load->model('poi_model');
    $this->load->library('session');
	}
	
	function list_poi()
	{
		$user_ses = $this->session->userdata('userlogindetails');
    
    if($user_ses['user_id'] && $user_ses['user_group']==1)
    {
	  	
	  	$displayform ='';
	  	$displayform .='<div id=dashboard ><span>Manage POI Details</span> <a href='.base_url().'/idea_home/admin_dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a><img align=right src="'.base_url().'images/back.png" alt="back" id=back ONCLICK="history.go(-1)" /></div>';
      $displayform .= '<span style="float:left;">Welcome '.$user_ses['user_name'].'</span><div id=logout><span id="create-state" style="cursor:pointer;color:blue;" ><a href="'.base_url().'poi/poi_add">Add New POI</a></span>&nbsp;<a href="'.base_url().'idea_home/logout">Logout</a></div>';
      $displayform .='<div align=right></div>';
	  	$displayform .='<br/>';
      
	  	$this->load->helper('flexigrid');
    
       
    $displayform .= '<table id="flex1" style="display:none" border=0 align=left ></table>';
    
    $colModel['poi_id'] = array('Sl No',100,TRUE,'center',0);
    $colModel['poi_desc'] = array('POI Details',150,TRUE,'center',2);
  
    $gridParams = array(
      'width' => 'auto',
      'height' => 400,
      'rp' => 15,
      'rpOptions' => '[10,20,30,40]',
      'pagestat' => 'Displaying:{from} to {to} of {total} items.',
      'blockOpacity' => 0.5,
      'title' => 'POI Details',
      'showTableToggleBtn' => true
    );
    
    $grid_js = build_grid_js('flex1',site_url("/ajax/poi_details"),$colModel,'poi_id','asc',$gridParams);
    
    $data['js_grid'] = $grid_js;  
    $data = array('formdisplay'=>$displayform,'js_grid'=>$grid_js );  
    $this->template->add_css('css/flexigrid/flexigrid.css');
    $this->template->add_js('js/flexigride/jquery.pack.js');
    $this->template->add_js('js/flexigride/flexigrid.pack.js');
    
    //model script comes here...
    
    
    
    //model script ends here
    
    //ends here....
    $this->template->write_view('header','header', $data, True);
    $this->template->write_view('content', 'general_flexigrid');
    $this->template->render();
    
    }
  else
  {
    echo "Forbidden to access!!";
  }		
	}	
	
	function poi_add()
	{
	  $user_ses = $this->session->userdata('userlogindetails');
    
    if($user_ses['user_id'] && $user_ses['user_group']==1)
    {
    
      		$poi_name = array('name'=>'poi_name','id'=>'poi_name',
      				'type'=>'text','class'=>'required');
      		$this->load->helper('form');
      		$this->load->library('form_validation');
      		$displayform ='';
      		$displayform .='<div id=dashboard ><span>Manage City</span> <a href='.base_url().'/idea_home/admin_dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a><img align=right src="'.base_url().'images/back.png" alt="back" id=back ONCLICK="history.go(-1)" /></div>';
          $displayform .= '<span style="float:left;">Welcome '.$user_ses['user_name'].'</span><div id=logout><a href="'.base_url().'idea_home/logout">Logout</a></div>';
          $displayform .= '<br/>';
      		$displayform .='<fieldset style="width:50%;"><legend>New POI Details</legend>';
      		$attr = array('id'=>'new_poi');
      		$displayform .= form_open('poi/poi_add',$attr);
      		$displayform .= '<table >';
      		$displayform .= '<tr><td align=left> POI Description:</td>';
      		$displayform .= '<td>'.form_input($poi_name).'</td>';
      		$displayform .= '</tr>';
      		$displayform .= '<tr><td align=right colspan=2>'.form_submit('submit','Create New POI').' '.form_reset('cancel','Cancel').'</td>';
      		$displayform .= '</tr>';
      		$displayform .= '</table></fieldset>';
      		$displayform .=form_close();
      		$this->form_validation->set_rules('poi_name', 'POI Name', 'trim|required|xss_clean');
      		//$displayform .= '<div align="right"><input type=button value="Go Back" ONCLICK="history.go(-1)" /></div>';
      		$data = array('formdisplay'=>$displayform );
      		//$this->template->add_js('js/jquery-1.3.2.js');
      		
      		if ($this->form_validation->run() == FALSE)
      		{		
      			$this->template->add_js('js/jquery-latest.js');	
      			$this->template->add_js('js/jquery.validate.js');
      			
      			$this->template->add_js('$(document).ready(function(){
      	 		   $("#new_poi").validate();
      	  			});
      		','embed');
      			$this->template->write_view('header','header', $data, True);
      			$this->template->write_view('content', 'general');
      			$this->template->render();
      		}
      		else
      		{
      			
      			$this->poi_model->insert_poi();
      			
      			redirect('poi/list_poi/0');
      			
      		}
      }
      else
      {
        echo "Forbidden to access!!";
      }
	}
	
	function duplicate_poi()
	{
	  $user_ses = $this->session->userdata('userlogindetails');
    
    if($user_ses['user_id'] && $user_ses['user_group']==1)
    {
    		$displayform ='';
    		$displayform .='<div id=dashboard ><span>Manage City</span> <a href='.base_url().'/idea_home/admin_dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a><img align=right src="'.base_url().'images/back.png" alt="back" id=back ONCLICK="history.go(-1)" /></div>';
    		$displayform .= "This POI DETAILS already exist,please go back and try for another name!!";
    		//$displayform .= '<div align="right"><input type=button value="Go Back" ONCLICK="history.go(-1)" /></div>';
    		$data = array('formdisplay'=>$displayform );
    		$this->template->write_view('header','header', $data, True);
    			$this->template->write_view('content', 'other_general');
    			$this->template->render();
    }
    else
    {
      echo "Forbidden to access!!";
    }      
	}
	
	function poi_edit($id=0)
	{
	  $user_ses = $this->session->userdata('userlogindetails');
    
    if($user_ses['user_id'] && $user_ses['user_group']==1)
    {
  		$this->load->helper('form');
  		$poi_name = $this->poi_model->poi_edit($id);
  		
  		$poi = $poi_name->result_array();
  		$poi_name = array('name'=>'poi_name','value'=>$poi[0]['poi_desc'],'type'=>'text','class'=>'required');
  		$displayform ='';
  		$displayform .='<div id=dashboard ><span>Manage City</span> <a href='.base_url().'/idea_home/admin_dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a><img align=right src="'.base_url().'images/back.png" alt="back" id=back ONCLICK="history.go(-1)" /></div>';
      $displayform .= '<span style="float:left;">Welcome '.$user_ses['user_name'].'</span><div id=logout><a href="'.base_url().'idea_home/logout">Logout</a></div>';
      $displayform .= '<br/>';
  		$displayform .='<fieldset style="width:50%;"><legend>Edit POI Details</legend>';
  		$attr = array('id'=>'edit_poi');
  		$displayform .= form_open('poi/save_edit',$attr);
  		$displayform .= '<input type=hidden name=id value='.$id.' />';
  		$displayform .= '<table class="tablestyle">';
  		$displayform .= '<tr><td align=left> POI Name:</td>';
  		$displayform .= '<td>'.form_input($poi_name).'</td>';
  		$displayform .= '</tr>';
  		
  		$displayform .= '<tr><td align=center colspan=2>'.form_submit('submit','Update POI').'</td>';
  		$displayform .= '</tr>';
  		$displayform .= '</table></fieldset>';
  		$displayform .=form_close();
  		//$displayform .= '<div align="right"><input type=button value="Go Back" ONCLICK="history.go(-1)" /></div>';
  		
  		$data = array('formdisplay'=>$displayform );
  		$this->template->write_view('header','header', $data, True);
  			$this->template->write_view('content', 'other_general');
  			$this->template->render();
  	}
    else
    {
      echo "Forbidden to Access!";
    }
    
  }  

	
	function save_edit()
	{
		$user_ses = $this->session->userdata('userlogindetails');
    
    if($user_ses['user_id'] && $user_ses['user_group']==1)
    {
    		$this->poi_model->edit_save();
    		redirect('poi/list_poi/0');
    }
    else
    {
      echo "forbidden to access!!";
    }

	}
}
